package com.mmaingenieria.GestorFacturacion.controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mmaingenieria.GestorFacturacion.beans.Cliente;

/**
 *
 * @author Mikle
 */
public class GestionClientesServlet extends HttpServlet {

    private static final String paginaClientes = "includes/gestionClientes.jsp";
    private static final String paginaError = "includes/login.jsp";

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost (request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        
    	
    	
    	ArrayList<Cliente> listaClientes = new ArrayList<Cliente>();
    	//TODO estabelcer conexion con la BBDD
    	Cliente cliente = new Cliente( 1,"on_social", "nombre_comercial", "direccion", "nif", "telefono1", "telefono2", 
    			                       "fax", "email", 2 , "telefono_fact", 2, "vuenta", 2, 
    			                       "observaciones", 0 , new Long("2").longValue() );
    	for ( int i=0; i <50; i++){
    		
    		listaClientes.add(cliente);
    	}
    	
    	
    	request.setAttribute("listaClientes", listaClientes );
        
    	RequestDispatcher dispatcher = null; //Creo variable dispatcher
        dispatcher = request.getRequestDispatcher(paginaClientes);//Le digo a donde tiene que ir
        dispatcher.forward(request, response);//Le digo que vaya
                
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
